package com.vue.controller.teacher;
import com.vue.dto.StudentDTO;
import com.vue.dto.TeacherDTO;
import com.vue.dto.TeacherPageQueryDTO;
import com.vue.entity.Student;
import com.vue.entity.Teacher;
import com.vue.result.PageResult;
import com.vue.result.Result;
import com.vue.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/teacherManage")
@Slf4j
@Api(tags = "教师管理相关接口")
public class T_ManageController {

    @Autowired
    private TeacherService teacherService;

    /**
     * 教师分页查询
     * @param teacherPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("教师分页查询")
    public Result<PageResult> studentPage(TeacherPageQueryDTO teacherPageQueryDTO){
        log.info("教师分页查询：{}", teacherPageQueryDTO);
        PageResult pageResult = teacherService.teacherPageQuery(teacherPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 根据id删除教师
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除教师")
    public Result deleteTeacher(@PathVariable Long id){
        log.info("根据id删除教师：{}",id);
        teacherService.deleteById(id);
        return Result.success();
    }

    /**
     * 添加教师
     * @param teacherDTO
     * @return
     */
    @PostMapping
    @ApiOperation("添加教师")
    public Result addStudent(@RequestBody TeacherDTO teacherDTO){
        log.info("添加教师：{}", teacherDTO);
        teacherService.add(teacherDTO);
        return Result.success();
    }

    /**
     * 修改教师
     * @param teacherDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改教师")
    public Result update(@RequestBody TeacherDTO teacherDTO){
        log.info("修改教师信息为：{}",teacherDTO);
        teacherService.update(teacherDTO);
        return Result.success();
    }
}
